<template>
    <ynet-content id="printDetail" :headerInformation="true" :headerMenu="true" >
        <div  v-if="main">
            <div>
                <el-form ref="queryForm" :model="queryForm" class="formEmbedTable mt20" :rules="rules">
                    <table>
                        <caption>Enquiry</caption>
                        <tr>
                            <td>TBS NUMBER FROM：</td>
                            <td>
                                <el-form-item  prop="startTime">
                                    <el-input v-model="queryForm.startTime"></el-input>
                                </el-form-item>              
                            </td>
                            <td>TO：</td>
                            <td>
                                <el-form-item  prop="endTime">
                                    <el-input v-model="queryForm.endTime"></el-input>
                                </el-form-item>             
                            </td>
                        </tr>	
                        <tr>
                            <td>Print status：</td>
                            <td colspan="3">
                                <el-form-item  prop="reqStatus">
                                    <el-select v-model="queryForm.reqStatus">
                                        <el-option label="All" value=""></el-option>
                                        <el-option label="Complete" value="C"></el-option>
                                        <el-option label="Not Ready" value="N"></el-option>
                                        <el-option label="Progress" value="P"></el-option>
                                    </el-select>
                                </el-form-item>              
                            </td>
                        </tr>		
                    </table>
                </el-form>
            </div>
            <div class="btnArea mt20 tac">
                <el-button type="primary" @click="queryChange('queryForm')">Search</el-button>
            </div>
            <div class="tableForm mt20  tableData">
                <el-table :data="tableData" border @select="handleSelectChange" ref="multipleTable">
                    <el-table-column type="selection"></el-table-column>
                    <el-table-column label="TBS No" prop="accNo" align="center"></el-table-column>
                    <el-table-column label="Authorized Persion" prop="receiver" align="center"></el-table-column>
                    <el-table-column label="Pint Status" prop="reqStatus" align="center">
                        <template scope="scope">
                            {{$tools.dict.reqStatus(scope.row.reqStatus)}}
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="btnArea mt20 tac">
                <el-button type="primary" @click="PrintFun()">Print</el-button>
                <el-button type="primary" @click="back()">Back</el-button>
            </div>
        </div>
        </div>
        <!--授权确认页面弹窗-->
        <div>
            <ynet-authDialog ref="dialogTable"  @getAuthForm="getAuthForm"></ynet-authDialog>
        </div>
    </ynet-content>
</template>

<script>
	export default {
		name:'printDetail',
		components:{
		},
        props:['batchNo'],
		data(){
            return { 
                main:true,turnPageTotalNum:'',
                rules:{
                    startDateObj: [
                        {trigger: 'blur', validator:this.$tools.validator.dateCompare,compareList:['startDateObj','endDateObj'],vm:this,formName:'queryForm'}
                    ],
                    endDateObj: [
                        {trigger: 'blur', validator:this.$tools.validator.dateCompare,compareList:['startDateObj','endDateObj'],vm:this,formName:'queryForm'}
                    ],
                },
                needAuth:'',
                authType:'', 
                tableData:[],
                authForm: { authUserNo: '', password: '',randomField:''},//100004   617100
                queryForm:{
                    startTime:'',
                    endTime:'',
                    bsnCode:'IM0406',
                    batchNo:this.batchNo,
                    reqStatus:'',
                },
                printBatchList:[],

            }   
        },
		methods:{ 
            resetForm(formName){
                this.$refs[formName].resetFields();
            },
            getAuthForm(val){
                //获取授权数据
                this.authForm=val;
                console.log("val:"+JSON.stringify(val))
                this.addForm=$.extend(this.addForm,this.authForm)
                this.typhoonAdd()  //自己页面提交给后台的.do方法
            },
            
            queryAuth(formName){//查询授权模式
                this.$refs[formName].validate((valid)=>{
                    if(valid){
                        let body={};body.bsnCode="IM0203";body.version="IM0203",
                        this.$tools.request(this,"IM010001Action.do",body).then(data=>{
                            if(data.body.errorCode==0){
                                if(data.body.needAuth==0){//无需授权
                                    this.typhoonAdd()
                                }else if(data.body.needAuth==1 && data.body.authType==1){
                                    this.needAuth=1;
                                    this.authType=1;
                                    this.$refs["dialogTable"].show()
                                            // this.dialogTableVisible=true;
                                }else if( data.body.needAuth==1 && data.body.authType==2 ){
                                    this.needAuth=1;
                                    this.authType=2;
                                    this.typhoonAdd()
                                }else{
                                    this.$alert('Authorization Type Error', {
                                        confirmButtonText: 'Confirm',
                                        callback: action => {
                                        }
                                    });
                                }
                            }else{
                                this.$alert("System Error Try again", "warning",{
                                    confirmButtonText: 'Confirm',
                                    callback: action => {
                                    }
                                });
                            }
                        })   
                    }
                })
                
			},
            back(){
                this.$emit('back')
            },
            PrintFun(){
                this.$tools.request(this,"IM0406Action.do",{printBatchList:this.printBatchList,actionType:'1',bsnCode:'IM0406'}).then(data=>{

                })
            },
            handleSelectChange(val,row){
                console.log("val:"+JSON.stringify(val))
                 console.log("row:"+JSON.stringify(row))
                this.printBatchList=val;
            },
            queryChange(){
                console.log("queryForm:"+JSON.stringify(this.queryForm))
                this.$tools.request(this,"IM0306DetailAction.do",this.queryForm).then(data=>{
                   console.log("data:"+JSON.stringify(data))
                   if(data.body.errorCode==0){
                        this.tableData=data.body.printBatchList;
                        //this.turnPageTotalNum=data.body.turnPageTotalNum;
                   }else{
                       this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                            callback: action => {
                            }
                        })
                   }
               })
            },
		}
	}
</script>